/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package OtherPubs;

import Rout.GoBefore;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.*;

public class MirrorCreator {

    private GoBefore browser = new GoBefore();
    private String filenames;
    private String refURL;

    @BeforeMethod
    public void setUp() throws Exception {
        
        System.out.println("\n Run test: " + getClass().getSimpleName());   
        browser.detctButton = false;
        browser.userAg = 1;
        browser.repDir = getClass().getSimpleName();
        browser.xpFilename = "//*[@id=\"content\"]/div[2]/div/div[1]/h3";
        browser.cssFilename = "#content > div.page > div > div.file > h3";
        browser.lpurl = "https://getsecuredfiles.com/mirrorc/gl2/";
    }

    @Test
    public void SmalButton() throws Exception {

        browser.curURL = "http://www.mirrorcreator.com/files/1YCOMLBD/temp._links";

        browser.clButton = "method_title";
        browser.cssButton = "#content > div.page > div > center > a > img";
        browser.xpButton = "//*[@id=\"content\"]/div[2]/div/center/a/img";

        browser.setUp();

        // get filename from prev test
        filenames = browser.filename_exp;

        browser.ipDetect();
        browser.testRun();                        
        
        browser.lpDetect();
        browser.verFilename();
        browser.takeFoto();
        browser.verFilePresent();

    }
//    @Test
//    public void SmalButton2() throws Exception {
//        
//        browser.detctButton = false;
//        
//        browser.curURL = "http://www.mirrorcreator.com/files/1YCOMLBD/temp._links";
//        browser.clButton = "";
//        browser.cssButton = "#content > div.page > div > center:nth-child(8) > a > img";
//        browser.xpButton = "//*[@id=\"content\"]/div[2]/div/center[1]/a/img";
//        browser.detctButton = false;
//
//        browser.setUp();
//        
//        //push the button and open it in new window       
//        WebElement link = browser.driver.findElement(By.cssSelector("#result > table > tbody > tr:nth-child(2) > td.dl_link > a > img"));
//        Actions newTab = new Actions(browser.driver);
//        newTab.keyDown(Keys.SHIFT).click(link).keyUp(Keys.SHIFT).build().perform();
//        Thread.sleep(5000);
//        //handle windows change
//        String base = browser.driver.getWindowHandle();
//        Set<String> set = browser.driver.getWindowHandles();
//        set.remove(base);        
//        browser.driver.switchTo().window((String) set.toArray()[0]);
//        System.out.println(browser.driver.getTitle() + " NEW URL is " + browser.driver.getCurrentUrl());
//
//        //find refURL
//        try {
//            refURL = browser.driver.findElement(By.xpath("//*[@id=\"redirectlink\"]/div")).getText();
//            System.out.println("EXP_refURL is: " + refURL);
//        } catch (Exception e) {
//            try {
//                refURL = browser.driver.getPageSource();
//                System.out.println("EXP_refURL is: " + refURL);
//            } catch (Exception e2) {
//                try {
//                    refURL = browser.driver.getTitle();
//                } catch (Exception e3) {                    
//                    refURL = "refURL not detect";
//                    System.out.println("WARNING: " + refURL);
//                    browser.Fail();
//                }
//            }
//        }
//        browser.testRun();
//        
//        
//        browser.CodeDetecter();
//      
//        browser.lpDetect();
//        
//        
//        System.out.println("LP url" + browser.lpurl);
//        
//        browser.CodeDetecter();
//        
//        //assert LPUrl contain refURL
//        try {
//            assert (browser.lpurl.contains(refURL));
//            System.out.println("Referral URL assert: OK");
//        } catch (AssertionError e) {
//            System.out.println("Filename assert: false (WRONG LP refURL:" + browser.lpurl + ")");
//         
//        }
//
//        browser.verFilename();
//        browser.verFilePresent();
//    }

    @AfterMethod
    public void ThearsDown() {
        browser.driver.quit();

    }

}
